package com.sky.mapper;

import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    /**
     * 添加一条订单数据
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据用户id查询所有订单
     * @param userId
     * @return
     */
    List<Orders> getOrdersByUserId(Long userId,Integer status);

    @Select("select * from orders where user_id = #{userId} and id = #{id}")
    Orders getOrderByUserAndId(Integer id, Long userId);

    /**
     * 自动处理超时订单
     * @param status
     * @param time
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime time);

    @Select("select * from orders where id = #{id}")
    Orders getOrderById(Long id);

    /**
     * 营业额统计
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     * 订单数量统计
     * @param map
     * @return
     */
    Integer getOrders(Map map);

    Integer countByMap(Map map);
}
